package com.xinxing.learning.batch.jobexecutor;

import com.xinxing.learning.batch.service.IncrementService;
import com.xinxing.learning.batch.service.batch.JobLauncherService;
import com.xinxing.learning.batch.util.JobUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class JobIncrementUserHandler {

    @Autowired
    private JobLauncherService jobLauncherService;

    @Autowired
    private IncrementService incrementService;

    @Autowired
    private Job incrementJob;

    @XxlJob("incrementUserJobHandler")
    public void incrementUserJobHandler() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
        JobUtil.runJob4Executor("incrementUser", incrementService, jobLauncherService, incrementJob);
    }
}
